package org.gap.dao;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.gap.domain.RelationsTiers;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage RelationsTiers entities.
 * 
 */
@Repository("RelationsTiersDAO")
@Transactional
public class RelationsTiersDAOImpl extends AbstractJpaDao<RelationsTiers>
		implements RelationsTiersDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { RelationsTiers.class }));

	/**
	 * EntityManager injected by Spring for persistence unit 
	 *
	 */
	@PersistenceContext(unitName = "")
	private EntityManager entityManager;

	/**
	 * Instantiates a new RelationsTiersDAOImpl
	 *
	 */
	public RelationsTiersDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findRelationsTiersByRltDateFinAfter
	 *
	 */
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltDateFinAfter(java.util.Calendar rltDateFin) throws DataAccessException {

		return findRelationsTiersByRltDateFinAfter(rltDateFin, -1, -1);
	}

	/**
	 * JPQL Query - findRelationsTiersByRltDateFinAfter
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltDateFinAfter(java.util.Calendar rltDateFin, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRelationsTiersByRltDateFinAfter", startResult, maxRows, rltDateFin);
		return new LinkedHashSet<RelationsTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRelationsTiersByRltDateFinBefore
	 *
	 */
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltDateFinBefore(java.util.Calendar rltDateFin) throws DataAccessException {

		return findRelationsTiersByRltDateFinBefore(rltDateFin, -1, -1);
	}

	/**
	 * JPQL Query - findRelationsTiersByRltDateFinBefore
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltDateFinBefore(java.util.Calendar rltDateFin, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRelationsTiersByRltDateFinBefore", startResult, maxRows, rltDateFin);
		return new LinkedHashSet<RelationsTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllRelationsTierss
	 *
	 */
	@Transactional
	public Set<RelationsTiers> findAllRelationsTierss() throws DataAccessException {

		return findAllRelationsTierss(-1, -1);
	}

	/**
	 * JPQL Query - findAllRelationsTierss
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RelationsTiers> findAllRelationsTierss(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllRelationsTierss", startResult, maxRows);
		return new LinkedHashSet<RelationsTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRelationsTiersByRltDateFin
	 *
	 */
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltDateFin(java.util.Calendar rltDateFin) throws DataAccessException {

		return findRelationsTiersByRltDateFin(rltDateFin, -1, -1);
	}

	/**
	 * JPQL Query - findRelationsTiersByRltDateFin
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltDateFin(java.util.Calendar rltDateFin, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRelationsTiersByRltDateFin", startResult, maxRows, rltDateFin);
		return new LinkedHashSet<RelationsTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRelationsTiersByRltRelation
	 *
	 */
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltRelation(String rltRelation) throws DataAccessException {

		return findRelationsTiersByRltRelation(rltRelation, -1, -1);
	}

	/**
	 * JPQL Query - findRelationsTiersByRltRelation
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltRelation(String rltRelation, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRelationsTiersByRltRelation", startResult, maxRows, rltRelation);
		return new LinkedHashSet<RelationsTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRelationsTiersByRltSens
	 *
	 */
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltSens(String rltSens) throws DataAccessException {

		return findRelationsTiersByRltSens(rltSens, -1, -1);
	}

	/**
	 * JPQL Query - findRelationsTiersByRltSens
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltSens(String rltSens, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRelationsTiersByRltSens", startResult, maxRows, rltSens);
		return new LinkedHashSet<RelationsTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRelationsTiersByRltDateDebutAfter
	 *
	 */
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltDateDebutAfter(java.util.Calendar rltDateDebut) throws DataAccessException {

		return findRelationsTiersByRltDateDebutAfter(rltDateDebut, -1, -1);
	}

	/**
	 * JPQL Query - findRelationsTiersByRltDateDebutAfter
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltDateDebutAfter(java.util.Calendar rltDateDebut, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRelationsTiersByRltDateDebutAfter", startResult, maxRows, rltDateDebut);
		return new LinkedHashSet<RelationsTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRelationsTiersByPrimaryKey
	 *
	 */
	@Transactional
	public RelationsTiers findRelationsTiersByPrimaryKey(Integer rltTiersParent, Integer rltTiersFils, String rltRelation) throws DataAccessException {

		return findRelationsTiersByPrimaryKey(rltTiersParent, rltTiersFils, rltRelation, -1, -1);
	}

	/**
	 * JPQL Query - findRelationsTiersByPrimaryKey
	 *
	 */

	@Transactional
	public RelationsTiers findRelationsTiersByPrimaryKey(Integer rltTiersParent, Integer rltTiersFils, String rltRelation, int startResult, int maxRows) throws DataAccessException {
		try {
			return executeQueryByNameSingleResult("findRelationsTiersByPrimaryKey", rltTiersParent, rltTiersFils, rltRelation);
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findRelationsTiersByRltRelationContaining
	 *
	 */
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltRelationContaining(String rltRelation) throws DataAccessException {

		return findRelationsTiersByRltRelationContaining(rltRelation, -1, -1);
	}

	/**
	 * JPQL Query - findRelationsTiersByRltRelationContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltRelationContaining(String rltRelation, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRelationsTiersByRltRelationContaining", startResult, maxRows, rltRelation);
		return new LinkedHashSet<RelationsTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRelationsTiersByRltTiersFils
	 *
	 */
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltTiersFils(Integer rltTiersFils) throws DataAccessException {

		return findRelationsTiersByRltTiersFils(rltTiersFils, -1, -1);
	}

	/**
	 * JPQL Query - findRelationsTiersByRltTiersFils
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltTiersFils(Integer rltTiersFils, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRelationsTiersByRltTiersFils", startResult, maxRows, rltTiersFils);
		return new LinkedHashSet<RelationsTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRelationsTiersByRltTiersParent
	 *
	 */
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltTiersParent(Integer rltTiersParent) throws DataAccessException {

		return findRelationsTiersByRltTiersParent(rltTiersParent, -1, -1);
	}

	/**
	 * JPQL Query - findRelationsTiersByRltTiersParent
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltTiersParent(Integer rltTiersParent, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRelationsTiersByRltTiersParent", startResult, maxRows, rltTiersParent);
		return new LinkedHashSet<RelationsTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRelationsTiersByRltDateDebutBefore
	 *
	 */
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltDateDebutBefore(java.util.Calendar rltDateDebut) throws DataAccessException {

		return findRelationsTiersByRltDateDebutBefore(rltDateDebut, -1, -1);
	}

	/**
	 * JPQL Query - findRelationsTiersByRltDateDebutBefore
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltDateDebutBefore(java.util.Calendar rltDateDebut, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRelationsTiersByRltDateDebutBefore", startResult, maxRows, rltDateDebut);
		return new LinkedHashSet<RelationsTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRelationsTiersByRltSensContaining
	 *
	 */
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltSensContaining(String rltSens) throws DataAccessException {

		return findRelationsTiersByRltSensContaining(rltSens, -1, -1);
	}

	/**
	 * JPQL Query - findRelationsTiersByRltSensContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltSensContaining(String rltSens, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRelationsTiersByRltSensContaining", startResult, maxRows, rltSens);
		return new LinkedHashSet<RelationsTiers>(query.getResultList());
	}

	/**
	 * JPQL Query - findRelationsTiersByRltDateDebut
	 *
	 */
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltDateDebut(java.util.Calendar rltDateDebut) throws DataAccessException {

		return findRelationsTiersByRltDateDebut(rltDateDebut, -1, -1);
	}

	/**
	 * JPQL Query - findRelationsTiersByRltDateDebut
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RelationsTiers> findRelationsTiersByRltDateDebut(java.util.Calendar rltDateDebut, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRelationsTiersByRltDateDebut", startResult, maxRows, rltDateDebut);
		return new LinkedHashSet<RelationsTiers>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(RelationsTiers entity) {
		return true;
	}
}
